From 1407199f890908912670e40e03ec91e338601b30 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Sat, 4 Mar 2006 10:32:10 +0100 Subject: [PATCH] Make guest_access implementation arch-specific. Signed-off-by: Keir Fraser --- xen/include/asm-ia64/guest_access.h | 63 +++++++++++++++++++++++++++++ xen/include/asm-x86/guest_access.h | 63 +++++++++++++++++++++++++++++ xen/include/public/arch-ia64.h | 22 ++++++++++ xen/include/public/arch-x86_32.h | 22 ++++++++++ xen/include/public/arch-x86_64.h | 22 ++++++++++ xen/include/public/xen.h | 22 ---------- xen/include/xen/guest_access.h | 49 +--------------------- 7 files changed, 193 insertions(+), 70 deletions(-) create mode 100644 xen/include/asm-ia64/guest_access.h create mode 100644 xen/include/asm-x86/guest_access.h diff --git a/xen/include/asm-ia64/guest_access.h b/xen/include/asm-ia64/guest_access.h new file mode 100644 index 0000000000..920476538e --- /dev/null +++ b/xen/include/asm-ia64/guest_access.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * guest_access.h + * + * Copyright (c) 2006, K A Fraser + */ + +#ifndef __ASM_IA64_GUEST_ACCESS_H__ +#define __ASM_IA64_GUEST_ACCESS_H__ + +#include + +/* Is the guest handle a NULL reference? */ +#define guest_handle_is_null(hnd) ((hnd).p == NULL) + +/* Offset the given guest handle into the array it refers to. */ +#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr)) + +/* Cast a guest handle to the specified type of handle. */ +#define guest_handle_cast(hnd, type) ({ \ + type *_x = (hnd).p; \ + (GUEST_HANDLE(type)) { _x }; \ +}) + +/* + * Copy an array of objects to guest context via a guest handle, + * specifying an offset into the guest array. + */ +#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ +}) + +/* + * Copy an array of objects from guest context via a guest handle, + * specifying an offset into the guest array. + */ +#define copy_from_guest_offset(ptr, hnd, off, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ +}) + +/* + * Pre-validate a guest handle. + * Allows use of faster __copy_* functions. + */ +#define guest_handle_okay(hnd, nr) \ + array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)) + +#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ +}) + +#define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ +}) + +#endif /* __ASM_IA64_GUEST_ACCESS_H__ */ diff --git a/xen/include/asm-x86/guest_access.h b/xen/include/asm-x86/guest_access.h new file mode 100644 index 0000000000..4b75af5bee --- /dev/null +++ b/xen/include/asm-x86/guest_access.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * guest_access.h + * + * Copyright (c) 2006, K A Fraser + */ + +#ifndef __ASM_X86_GUEST_ACCESS_H__ +#define __ASM_X86_GUEST_ACCESS_H__ + +#include + +/* Is the guest handle a NULL reference? */ +#define guest_handle_is_null(hnd) ((hnd).p == NULL) + +/* Offset the given guest handle into the array it refers to. */ +#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr)) + +/* Cast a guest handle to the specified type of handle. */ +#define guest_handle_cast(hnd, type) ({ \ + type *_x = (hnd).p; \ + (GUEST_HANDLE(type)) { _x }; \ +}) + +/* + * Copy an array of objects to guest context via a guest handle, + * specifying an offset into the guest array. + */ +#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ +}) + +/* + * Copy an array of objects from guest context via a guest handle, + * specifying an offset into the guest array. + */ +#define copy_from_guest_offset(ptr, hnd, off, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ +}) + +/* + * Pre-validate a guest handle. + * Allows use of faster __copy_* functions. + */ +#define guest_handle_okay(hnd, nr) \ + array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)) + +#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ +}) + +#define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \ + const typeof(ptr) _x = (hnd).p; \ + const typeof(ptr) _y = (ptr); \ + __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ +}) + +#endif /* __ASM_X86_GUEST_ACCESS_H__ */ diff --git a/xen/include/public/arch-ia64.h b/xen/include/public/arch-ia64.h index 199b3acff6..1c7b286b47 100644 --- a/xen/include/public/arch-ia64.h +++ b/xen/include/public/arch-ia64.h @@ -7,6 +7,28 @@ #ifndef __HYPERVISOR_IF_IA64_H__ #define __HYPERVISOR_IF_IA64_H__ +#ifdef __XEN__ +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef struct { type *p; } __guest_handle_ ## name +#else +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef type * __guest_handle_ ## name +#endif + +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name) +#define GUEST_HANDLE(name) __guest_handle_ ## name + +#ifndef __ASSEMBLY__ +/* Guest handles for primitive C types. */ +__DEFINE_GUEST_HANDLE(uchar, unsigned char); +__DEFINE_GUEST_HANDLE(uint, unsigned int); +__DEFINE_GUEST_HANDLE(ulong, unsigned long); +DEFINE_GUEST_HANDLE(char); +DEFINE_GUEST_HANDLE(int); +DEFINE_GUEST_HANDLE(long); +DEFINE_GUEST_HANDLE(void); +#endif + /* Maximum number of virtual CPUs in multi-processor guests. */ /* WARNING: before changing this, check that shared_info fits on a page */ #define MAX_VIRT_CPUS 4 diff --git a/xen/include/public/arch-x86_32.h b/xen/include/public/arch-x86_32.h index 9ae1494699..17e40647a0 100644 --- a/xen/include/public/arch-x86_32.h +++ b/xen/include/public/arch-x86_32.h @@ -9,6 +9,28 @@ #ifndef __XEN_PUBLIC_ARCH_X86_32_H__ #define __XEN_PUBLIC_ARCH_X86_32_H__ +#ifdef __XEN__ +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef struct { type *p; } __guest_handle_ ## name +#else +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef type * __guest_handle_ ## name +#endif + +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name) +#define GUEST_HANDLE(name) __guest_handle_ ## name + +#ifndef __ASSEMBLY__ +/* Guest handles for primitive C types. */ +__DEFINE_GUEST_HANDLE(uchar, unsigned char); +__DEFINE_GUEST_HANDLE(uint, unsigned int); +__DEFINE_GUEST_HANDLE(ulong, unsigned long); +DEFINE_GUEST_HANDLE(char); +DEFINE_GUEST_HANDLE(int); +DEFINE_GUEST_HANDLE(long); +DEFINE_GUEST_HANDLE(void); +#endif + /* * SEGMENT DESCRIPTOR TABLES */ diff --git a/xen/include/public/arch-x86_64.h b/xen/include/public/arch-x86_64.h index bfd5f33d31..d907eea474 100644 --- a/xen/include/public/arch-x86_64.h +++ b/xen/include/public/arch-x86_64.h @@ -9,6 +9,28 @@ #ifndef __XEN_PUBLIC_ARCH_X86_64_H__ #define __XEN_PUBLIC_ARCH_X86_64_H__ +#ifdef __XEN__ +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef struct { type *p; } __guest_handle_ ## name +#else +#define __DEFINE_GUEST_HANDLE(name, type) \ + typedef type * __guest_handle_ ## name +#endif + +#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name) +#define GUEST_HANDLE(name) __guest_handle_ ## name + +#ifndef __ASSEMBLY__ +/* Guest handles for primitive C types. */ +__DEFINE_GUEST_HANDLE(uchar, unsigned char); +__DEFINE_GUEST_HANDLE(uint, unsigned int); +__DEFINE_GUEST_HANDLE(ulong, unsigned long); +DEFINE_GUEST_HANDLE(char); +DEFINE_GUEST_HANDLE(int); +DEFINE_GUEST_HANDLE(long); +DEFINE_GUEST_HANDLE(void); +#endif + /* * SEGMENT DESCRIPTOR TABLES */ diff --git a/xen/include/public/xen.h b/xen/include/public/xen.h index 706e8000c1..9baf7f0bbe 100644 --- a/xen/include/public/xen.h +++ b/xen/include/public/xen.h @@ -9,28 +9,6 @@ #ifndef __XEN_PUBLIC_XEN_H__ #define __XEN_PUBLIC_XEN_H__ -#ifdef __XEN__ -#define __DEFINE_GUEST_HANDLE(name, type) \ - typedef struct { type *p; } __guest_handle_ ## name -#else -#define __DEFINE_GUEST_HANDLE(name, type) \ - typedef type * __guest_handle_ ## name -#endif - -#define DEFINE_GUEST_HANDLE(name) __DEFINE_GUEST_HANDLE(name, name) -#define GUEST_HANDLE(name) __guest_handle_ ## name - -#ifndef __ASSEMBLY__ -/* Guest handles for primitive C types. */ -__DEFINE_GUEST_HANDLE(uchar, unsigned char); -__DEFINE_GUEST_HANDLE(uint, unsigned int); -__DEFINE_GUEST_HANDLE(ulong, unsigned long); -DEFINE_GUEST_HANDLE(char); -DEFINE_GUEST_HANDLE(int); -DEFINE_GUEST_HANDLE(long); -DEFINE_GUEST_HANDLE(void); -#endif - #if defined(__i386__) #include "arch-x86_32.h" #elif defined(__x86_64__) diff --git a/xen/include/xen/guest_access.h b/xen/include/xen/guest_access.h index 3a5bba9f0b..0b9fb071a4 100644 --- a/xen/include/xen/guest_access.h +++ b/xen/include/xen/guest_access.h @@ -7,64 +7,17 @@ #ifndef __XEN_GUEST_ACCESS_H__ #define __XEN_GUEST_ACCESS_H__ -#include +#include -/* Is the guest handle a NULL reference? */ -#define guest_handle_is_null(hnd) ((hnd).p == NULL) - -/* Offset the given guest handle into the array it refers to. */ -#define guest_handle_add_offset(hnd, nr) ((hnd).p += (nr)) - -/* Cast a guest handle to the specified type of handle. */ -#define guest_handle_cast(hnd, type) ({ \ - type *_x = (hnd).p; \ - (GUEST_HANDLE(type)) { _x }; \ -}) - -/* - * Copy an array of objects to guest context via a guest handle. - * Optionally specify an offset into the guest array. - */ -#define copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ -}) #define copy_to_guest(hnd, ptr, nr) \ copy_to_guest_offset(hnd, 0, ptr, nr) -/* - * Copy an array of objects from guest context via a guest handle. - * Optionally specify an offset into the guest array. - */ -#define copy_from_guest_offset(ptr, hnd, off, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ -}) #define copy_from_guest(ptr, hnd, nr) \ copy_from_guest_offset(ptr, hnd, 0, nr) -/* - * Pre-validate a guest handle. - * Allows use of faster __copy_* functions. - */ -#define guest_handle_okay(hnd, nr) \ - array_access_ok((hnd).p, (nr), sizeof(*(hnd).p)) - -#define __copy_to_guest_offset(hnd, off, ptr, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - __copy_to_user(_x+(off), _y, sizeof(*_x)*(nr)); \ -}) #define __copy_to_guest(hnd, ptr, nr) \ __copy_to_guest_offset(hnd, 0, ptr, nr) -#define __copy_from_guest_offset(ptr, hnd, off, nr) ({ \ - const typeof(ptr) _x = (hnd).p; \ - const typeof(ptr) _y = (ptr); \ - __copy_from_user(_y, _x+(off), sizeof(*_x)*(nr)); \ -}) #define __copy_from_guest(ptr, hnd, nr) \ __copy_from_guest_offset(ptr, hnd, 0, nr) -- 2.30.2